package com.core;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AjaxDispatch extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AjaxDispatch() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String method = request.getParameter("method");
		if (method != null && !method.trim().equals("")) {
			try {
//				if(method.equals("getSessionByStaff") || method.equals("delQGrid") || method.equals("delAdvInfo")){
//					AjaxHandleMethod.class.getMethod(method.trim(),
//							new Class[] {HttpServletRequest.class, HttpServletResponse.class, ServletContext.class}).invoke(
//							new AjaxHandleMethod(),new Object[] {request, response, this.getServletContext()});
//				}else{
//					AjaxHandleMethod.class.getMethod(method.trim(),
//						new Class[] {HttpServletRequest.class, HttpServletResponse.class}).invoke(
//						new AjaxHandleMethod(),new Object[] {request, response});
//				}
				AjaxHandleMethod.class.getMethod(method.trim(),
						new Class[] {HttpServletRequest.class, HttpServletResponse.class, ServletContext.class}).invoke(
						new AjaxHandleMethod(),new Object[] {request, response, this.getServletContext()});
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (SecurityException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
